//
//  XS_BaseTableCell.swift
//  
//
//  Created by 韩云智 on 2021/10/5.
//

import UIKit
import RxCocoa
import RxSwift
import SnapKit

open class XS_BaseTableCell: UITableViewCell {
    open lazy var disposeBag = DisposeBag()
    /// 单元格重用时会重置
    open lazy var reuseDisposeBag = DisposeBag()
    //单元格重用时调用
    open override func prepareForReuse() {
        super.prepareForReuse()
        reuseDisposeBag = DisposeBag()
    }
    
    deinit {
#if DEBUG
        print("deinit: \(type(of: self))")
#endif
    }
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
#if DEBUG
        print("init: \(type(of: self))")
#endif
        upView(reuseIdentifier)
    }
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open func upView(_ reuseIdentifier: String?) {
        selectionStyle = UITableViewCell.SelectionStyle.none // 去掉点击样式
        backgroundColor = Base_hanyz.backgroundColor
    }
    
    /// 自定义Cell分割线
    open lazy var line = UIView()
    /// 分割线样式
    open func loadLine(_ color: UIColor = Base_hanyz.lineColor,
                         height: CGFloat = 1.0/UIScreen.main.scale,
                         left: CGFloat = 0,
                         right: CGFloat = 0,
                         offset: CGFloat = 1.0/UIScreen.main.scale,
                         isTop: Bool = true) {
        line.backgroundColor = color
        addSubview(line)
        line.snp.makeConstraints {
            if isTop {
                $0.top.equalToSuperview().offset(offset)
            } else {
                $0.bottom.equalToSuperview().offset(-offset)
            }
            $0.right.equalTo(-right)
            $0.left.equalTo(left)
            $0.height.equalTo(height)
        }
    }
    
    open override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    open override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
}
